{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = [{'faceId': 'b369e6af-1b7f-4158-aaef-cd9a31fe763b',\n",
    "  'faceRectangle': {'top': 45, 'left': 37, 'width': 89, 'height': 89},\n",
    "  'faceAttributes': {'smile': 1.0,\n",
    "   'headPose': {'pitch': 1.9, 'roll':1.1, 'yaw': -9.0},\n",
    "   'gender': 'male',\n",
    "   'age': 22.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.0,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 1.0,\n",
    "    'neutral': 0.0,\n",
    "    'sadness': 0.0,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.67},\n",
    "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
    "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.02,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'red', 'confidence': 0.99},\n",
    "     {'color': 'brown', 'confidence': 0.89},\n",
    "     {'color': 'blond', 'confidence': 0.67},\n",
    "     {'color': 'other', 'confidence': 0.55},\n",
    "     {'color': 'gray', 'confidence': 0.04},\n",
    "     {'color': 'black', 'confidence': 0.01},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': '795fbebe-ae48-44a2-b2df-27fae88ece12',\n",
    "  'faceRectangle': {'top': 67, 'left': 326, 'width': 82, 'height': 82},\n",
    "  'faceAttributes': {'smile': 1.0,\n",
    "   'headPose': {'pitch': -8.5, 'roll': -10.1, 'yaw': -7.5},\n",
    "   'gender': 'male',\n",
    "   'age': 21.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.0,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 1.0,\n",
    "    'neutral': 0.0,\n",
    "    'sadness': 0.0,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'low', 'value': 0.2},\n",
    "   'exposure': {'exposureLevel': 'overExposure', 'value': 0.76},\n",
    "   'noise': {'noiseLevel': 'low', 'value': 0.05},\n",
    "   'makeup': {'eyeMakeup': True, 'lipMakeup': False},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.06,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'brown', 'confidence': 1.0},\n",
    "     {'color': 'red', 'confidence': 0.56},\n",
    "     {'color': 'blond', 'confidence': 0.37},\n",
    "     {'color': 'black', 'confidence': 0.15},\n",
    "     {'color': 'gray', 'confidence': 0.13},\n",
    "     {'color': 'other', 'confidence': 0.02},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': '2a08f17f-adef-47fe-a13c-bc53ac80814d',\n",
    "  'faceRectangle': {'top': 83, 'left': 222, 'width': 79, 'height': 79},\n",
    "  'faceAttributes': {'smile': 1.0,\n",
    "   'headPose': {'pitch': -5.9, 'roll': 4.1, 'yaw': 2.4},\n",
    "   'gender': 'female',\n",
    "   'age': 19.0,\n",
    "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.0,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 1.0,\n",
    "    'neutral': 0.0,\n",
    "    'sadness': 0.0,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'medium', 'value': 0.52},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.64},\n",
    "   'noise': {'noiseLevel': 'low', 'value': 0.21},\n",
    "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.01,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'brown', 'confidence':1.0},\n",
    "     {'color': 'blond', 'confidence': 0.98},\n",
    "     {'color': 'red', 'confidence': 0.67},\n",
    "     {'color': 'gray', 'confidence': 0.12},\n",
    "     {'color': 'other', 'confidence': 0.02},\n",
    "     {'color': 'black', 'confidence': 0.01},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 建立字典\n",
    "glasses = {}\n",
    "hairColor = {}\n",
    "smile = {}\n",
    "age = {}\n",
    "gender = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把所有人脸的值添加进字典\n",
    "count = 0\n",
    "while count < len(r):\n",
    "    glasses[\"Person{}\".format(count + 1)] = r[count]['faceAttributes']['glasses']\n",
    "    hairColor[\"Person{}\".format(count + 1)] = r[count]['faceAttributes']['hair']['hairColor'][0]['color']\n",
    "    smile[\"Person{}\".format(count + 1)] = r[count]['faceAttributes']['smile']\n",
    "    age[\"Person{}\".format(count + 1)] = r[count]['faceAttributes']['age']\n",
    "    gender[\"Person{}\".format(count + 1)] = r[count]['faceAttributes']['gender']\n",
    "    count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "眼镜： {'Person1': 'NoGlasses', 'Person2': 'NoGlasses', 'Person3': 'NoGlasses'}\n",
      "头发颜色： {'Person1': 'red', 'Person2': 'brown', 'Person3': 'brown'}\n",
      "微笑指数： {'Person1': 1.0, 'Person2': 1.0, 'Person3': 1.0}\n",
      "年龄： {'Person1': 22.0, 'Person2': 21.0, 'Person3': 19.0}\n",
      "性别： {'Person1': 'male', 'Person2': 'male', 'Person3': 'female'}\n"
     ]
    }
   ],
   "source": [
    "# 打印字典\n",
    "print(\"眼镜：\", glasses)\n",
    "print(\"头发颜色：\", hairColor)\n",
    "print(\"微笑指数：\", smile)\n",
    "print(\"年龄：\", age)\n",
    "print(\"性别：\", gender)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
